load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//bazel:copts.bzl", "copts")
load("//bazel:malloc.bzl", "malloc")

cc_library(
    name = "generate-test-task-name",
    hdrs = [
        "generate-test-task-name.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "@com_github_google_googletest//:gtest",
    ],
)

cc_library(
    name = "promisify-for-test",
    hdrs = [
        "promisify-for-test.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":generate-test-task-name",
        "//eventuals",
        "@com_github_google_googletest//:gtest",
    ],
)

cc_library(
    name = "event-loop-test",
    hdrs = [
        "event-loop-test.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//eventuals",
        "@com_github_google_googletest//:gtest",
    ],
)

cc_library(
    name = "http-mock-server",
    testonly = True,
    srcs = ["http-mock-server.cc"],
    hdrs = ["http-mock-server.h"],
    copts = copts(),
    deps = [
        "//eventuals",
        "@com_github_chriskohlhoff_asio//:asio",
        "@com_github_google_googletest//:gtest",
    ],
)

cc_test(
    name = "eventuals",
    srcs = [
        "bitwise_operator.cc",
        "callback.cc",
        "catch.cc",
        "closure.cc",
        "collect.cc",
        "compose.cc",
        "conditional.cc",
        "control-loop.cc",
        "dns-resolver.cc",
        "do-all.cc",
        "eventual.cc",
        "executor.cc",
        "expected.cc",
        "filesystem.cc",
        "filter.cc",
        "finally.cc",
        "flat-map.cc",
        "foreach.cc",
        "fork-join.cc",
        "generator.cc",
        "http.cc",
        "if.cc",
        "iterate.cc",
        "just.cc",
        "let.cc",
        "lock.cc",
        "notification.cc",
        "on-begin.cc",
        "on-ended.cc",
        "os.cc",
        "pipe.cc",
        "poll.cc",
        "range.cc",
        "repeat.cc",
        "request-response-channel.cc",
        "signal.cc",
        "static-thread-pool.cc",
        "stream.cc",
        "take.cc",
        "task.cc",
        "then.cc",
        "timer.cc",
        "transformer.cc",
        "type-check.cc",
        "type-traits.cc",
        "unpack.cc",
    ],
    copts = copts(),
    # Use a faster implementation of malloc (and show that tests pass with it).
    malloc = malloc(),
    deps = [
        ":generate-test-task-name",
        ":http-mock-server",
        ":promisify-for-test",
        ":event-loop-test",
        "//eventuals",
        "//test/concurrent",
        "@com_github_google_googletest//:gtest_main",
    ] + select(
        {
            # We support backward lib only for Linux.
            # The support for Windows and MacOS might be added in future.
            # https://github.com/3rdparty/eventuals/issues/450
            # https://github.com/3rdparty/eventuals/issues/616
            "@platforms//os:linux": [
                "@com_github_3rdparty_bazel_rules_backward_cpp_stacktrace//:backward-stacktrace",
            ],
            "//conditions:default": [],
        },
    ),
)
